package com.lelefly.base.utils;


import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class ThreadUtil {
    private static final int MAX_THREAD_COUNT = 3;
    private static ExecutorService pool_ = Executors.newFixedThreadPool(MAX_THREAD_COUNT);
    
    public static void execute(Runnable task) {
    	pool_.execute(task);
    }

	public static Object executeAndReturn(Callable<?> callable) {
		Future<?> future = pool_.submit(callable);
		try {
			return future.get();
		} catch (Exception e) {

		}
		return null;
	}
    
    public static void sleep(int seconds) {
    	for (int i = 0; i < seconds; i++) {
    		try {
    			Thread.sleep(1000);
    		} catch (Exception e) {
    		}
    	}
    }
}
